home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
diskmags
/
3565-4.665
/
dmg-3609
/
news.txt
/
project4.asc
< prev
next >
Wrap
Text File
|
1989-04-05
|
17KB
|
404 lines
##########################
# #
# DIGITAL JUNCTION #
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ #
# INTERFACING 4 #
# ¯¯¯¯¯¯¯¯¯¯¯¯¯ #
# #
# by Dave Price #
# #
##########################
Over the past few instalment of Interfacing I have discussed various
possibilities that would enable the transfer of data between the ST and
outside world.
We are now going to put this knowledge to use by carrying out some
practical interfacing experiments. Whilst I shall be basing the software
and hardware around the use of the cartridge and printer ports there is
no reason why the experiments cannot be carried out on other types of
interface units such as the Maplin RS232 to 8-bit I/O port as the
principles are the same although the software may well need altering to
suit.
Before starting I must draw your attention to an amendment that
needs to be made to the suggested printer port module (see STEN 12). I
had missed out a component in my circuit diagram. The diagram should have
shown a transistor on the strobe line. It is important that the
transistor is installed as it provides buffering to the strobe line and
protects the sound chip from possible damage. See picture
file..USEPORT2.PC3 (<SCREENS> folder).
The first project will prove to be a useful little tool as it
provides a visual display of what is going on at the output port and thus
can be very helpful for checking that the port or software is doing what
is intended.
PROJECT No.1 - Output Display Unit
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Basic parts list
1 piece of stripboard 10 strips wide x 15 holes long
8 Red LED (rectangular makes neat job but 3mm dia. will do
1 180R 9-pin SIL resistor array (9 pins- 8 resistors 1 common)
1 ULN2803A Octal Darlington Driver TTL **SEE NOTE BELOW
1 18-pin DIL socket
length of 10-way ribbon cable or other flexible insulated wire
NOTE: Above parts are for an 8-bit wide port. If you require 16-bit
double up on components and double width of stripboard.
ULN2803A not absolutly necessary if using buffered output.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
See picture file..PROJECT1.PC3..(<SCREENS> folder) for layout.
Having built the circuit check for component orientation, solder
bridges and cuts in stripboard have been made in the correct places. Now
connect the project to your interface unit making sure connecting wires
are in the correct order or if using plugs that they are wired correctly.
NOTE: If you are connecting the project directly to the printer port you
will need a 25-way 'D' type plug. In either case do not forget to connect
your 5 volt D.C. supply.
**WARNING** - Any peripherals including interfacing projects must be
connected before powering up your ST.
Upon switching on your ST you may notice that the LEDs flash on and
off once. This is OK it is only the system setting its self. There may be
occasion when one or two LEDS may stay on, again, don't worry it is
possible that a spurious pulse may have caused a line to latch on. This
can be cleared by sending a zero to the port as follows:-Listings in GFA
BASIC V3.6
RESETTING PRINTER PORT - Using hardware as discussed in Interface 3
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
~XBIOS(30,$20) !Switch userport to write mode (See note below)
~XBIOS(28,0,$81) !Send zero to port
NOTE: ~XBIOS(30,$20) not needed if project is directly connected to
printer port. See Interface 3 (STEN 12) for explanation of XBIOS
routines.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RESETTING CARTRIDGE PORT - Using hardware as discussed in Interface 3
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
DEFFN portout(d%) = PEEK(&HFA0000+d%) !ROM4 select + output data in d%
~@portout(0) !Send zero to port
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All LEDs should now be off indicating that all output lines are at
logic low (0 Volts).
This next program is just a little test to check each data line (D0 to
D7) is operating correctly.
(a) Printer Port
CLS
~XBIOS(30,$20) !Set userport hardware to output mode
DO
LOCATE 10,5
PRINT" THIS ALLOWS YOU TO SET ONE OF THE OUTPUT"
PRINT TAB(9);"LINES(D0 - D7) ON THE PRINTER PORT"
PRINT TAB(9);"ENTER -1 TO SWITCH OFF ALL LINES"
PRINT TAB(9);"PRESS RETURN TO EXIT"
LOCATE 10,12
INPUT"ENTER OUTPUT LINE (0 -7) TO SET ";a$
EXIT IF a$=""
n|=VAL(a$)
x|=2^n|
~XBIOS(28,x|,$8F) !Output data in x|
Loop
~XBIOS(28,0,$8F) !Reset output (all LEDs off)
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(b) Cartridge port
DEFFN portout(d%)=PEEK(&HFA0000+d%)
CLS
DO
LOCATE 10,5
PRINT" THIS ALLOWS YOU TO SET ONE OF THE OUTPUT"
PRINT TAB(9);"LINES(D0 - D15) ON THE CARTRIDGE PORT"
PRINT TAB(9);"ENTER -1 TO SWITCH OFF ALL LINES"
PRINT TAB(9);"PRESS RETURN TO EXIT"
LOCATE 10,12
INPUT"ENTER OUTPUT LINE (0 - 15) TO SET ";a$
EXIT IF a$=""
n%=VAL(a$)
x%=2^n%
~@portout(x%) !Output data in x%
LOOP
~@portout(0) !Reset output (all LEDs off)
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you have wired the LED module correctly, the number you enter
into the program should turn the corresponding LED on indicating that the
line has been set to logic high (+5 volts) i.e. entering 3 will set data
line D3 and therefore the corresponding LED will be on. You may have
noticed the terms SET and RESET being used when discussing digital logic
levels. Generally, a digital line is SET when at logic high (1) and RESET
when at logic low (0).
Now try the the following program:-
Printer Port
CLS
~XBIOS(30,$20)
FOR x|=0 TO 255
PRINT x|; HEX$(x|)
~XBIOS(28,x|,$8F)
DELAY 5
NEXT x|
PRINT"Press any key to exit"
~INP(2)
~XBIOS(28,0,$8F)
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cartridge Port
DEFFN portout(d%)=PEEK(&HFA0000+d%)
CLS
FOR x%=0 TO 65535
PRINT x%; HEX$(x%)
~@portout(x%)
DELAY 5 ! wait for 5 seconds
NEXT x%
PRINT"Press any key to exit"
~INP(2)
~@portout(0)
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Running this program will cause a list of decimal numbers from 0 to
255 (65535 if using 16-bit on cartridge port) along with their
hexidecimal equivalents 00 to FF (FFFF if 16-bit) to be displayed on
screen. At the same time the LEDs will display the binary equivalents as
the numbers increase. The program has a 5 second delay between each
number which should be ample time to note the number displayed on the
screen and the LED pattern. To change the delay time just alter program
line DELAY 5.
The following program is a little more exciting. It "walks" a light
along the row of LEDs in the same fashion used by many advertising signs.
NOTE: To save repetition I shall, from now on, only be providing listings
for use with the suggested printer port interface. Anyone using the
cartridge port should not have any difficulty in converting the programs
to suit. The previous programs should serve as a guide. If any new
routines not mentioned before do arise then I shall indicate in the
printer port listings where any alterations may need to be carried out.
However, If anyone has problems then let me know.
Running light program
PRINT "Press mouse button to exit"
REPEAT
x=1
REPEAT
~XBIOS(28,x|,$8F)
PAUSE 5 x=x*2
UNTIL x=256
UNTIL MOUSEK
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These small programs should give a reasonable indication as to how
easy it is to send data and control signals from the ST. We shall now
move onto simple inputting of data but before we do another small circuit
needs to be built.
Components list for Input switch module
1 stripboard 10 strips x 15 holes
1 octal DIL switch
1 16-pin DIL socket
1 100k 9-pin SIL resistor network
wire and connectors for data and power lines.
See picture file..PROJECT2.PC3..(<SCREENS folder) for layout.
Double up on the quantity for 16-bit inputs.
Connect the new circuit to your interface unit or directly to
printer port and set DIL switches in the OFF position. Now type in and
run the following GFA BASIC V3.6 program:-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~XBIOS(29,$DF) !Resets strobe line low to switch suggested printer
port !interface to input mode.
r|=XBIOS(28,0,$0F)!switches printer port data lines to input and places
!data in r|
PRINT "Data on input port reads";r|
PRINT "Press any key to exit"
~INP(2)
~XBIOS(28,0,$8F) ! Reset printer port to output as per normal system
! setting
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cartridge port users should use r%=DPEEK(&HFB0000) instead of XBIOS
routine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The program should display a zero indicating all input lines are at
logic 0. If you now switch any amount of the switches on and run the
program again the screen will display the decimal number equivalent of
the switch settings. The switches that are in the on position sets the
relevant input line (logic 1). For example, if the switches on D7, D3 &
D0 input lines are on and the rest are off the binary number 10001001
will be present at the input port. Running the above program will display
137, the decimal equivalent.
It would be very useful to be able to combine the input and output
of data i.e. monitor the input signals, process them and then output as
required. This cannot be done by direct connection to the printer port as
the 8-bit data lines can only be set for input or output, they cannot be
mixed. I therefore suggest that the circuit outlined or similar in the
last installment is used. Cartridge port users are ok as separate input
and output lines are available. See previous digital junctions for
further information.
Carrying out input and output of data together is straight foward.
Connect the LED module into your output port, the switch module to the
input port and run the program listed below. The program simpley reads
the input port, prints the decimal and hex value on screen then displays
the binary value on the LED module.
INPUT/OUTPUT Program.
~XBIOS(29,$DF) !strobe low - interface port to input mode
r=XBIOS(28,0,$0F) !data in and store in r
PRINT "DATA ON INPUT READS ";r,HEX$(r)
~XBIOS(30,$20) !strobe high - interface port to output mode
~XBIOS(28,r,$8F) !output data
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This program can be placed in a loop to save having to constantly
run it every time you change the switch pattern, I leave that to you.
The above example is really no more than a glorified switch but does
demonstrate the basic principles. The last example for this installment
is a little more sophisticated. It demonstrates the principles of how a
computer can be used to continuously monitor its input port and only
react when a certain code is received, rather like an electronic coded
lock.
Lock program
code=143 ! or any number between 0 and 255
REPEAT
~XBIOS(30,$20) ! strobe high
~XBIOS(28,255,$8F) ! set all LEDs on
DELAY 0.5 ! delay for half second
~XBIOS(28,0,$8F) ! all LEDs off
~XBIOS(29,$DF) ! strobe low
~XBIOS(28,0,$0F) ! read input
UNTIL r=code
~XBIOS(30,$20) ! strobe high
~XBIOS(28,255,$8F) ! set all LEDs on
SOUND 1,15,1,4,20
SOUND 2,15,4,4,20 ! make a noise
SOUND 3,15,8,4,20
WAVE 7,7,0,65535,300
PRINT "YOU MAY NOW ENTER"
PRINT
PRINT "PRESS ANY KEY TO EXIT PROGRAM"
~INP(2)
~XBIOS(28,0,$8F) ! all LEDs off
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This program flashes the LEDs and monitors the input port. As soon
as the input data, set by the switches, matches the number stored in
variable 'code' (143 decimal or 10001111 binary i.e. switches for lines
D7,D3,D2,D1,D0 set on all others off in our example) the program exits
the REPEAT - UNTIL loop, sets all the LEDs on, makes a noise and displays
a message.
Well thats it for this issue. I hope you have found the examples and
circuits easy to follow, I have tried to keep things simple. If you have
any problems then please get in touch. The program listings have been
kept to the bare minimum in order that you can see whats going on, if you
want to write your own with GEM buttons etc then do so there is nothing
stopping you. Also don't be afraid to experiment, how about writing a
program to simulate traffic lights at a junction using the switches to
simulate the induction loop vehicle sensors buried in the road.
Next Issue
---------- I hope to discuss the methods required to enable control
of filement lamps (as opposed to LEDs) and electric motors including
stepper motors.
Notice Board
------------ Unless otherwise stated, all modifications, experiments,
hardware and software discussed in this column are tested on a 1 Meg
Atari STFM with high resolution monitor. However, the projects and
software should work on most other set ups as I have tried to keep things
to standard.
If you should spot an error or know of a better way of achieving
something be it with hardware or software then please let me know so
that I may pass the knowledge on through this column. What may seem
obvious to you may have been over looked by others and could be just the
answer they are looking for.
STEN is here because enthusiasts are willing to pass on what they
know.
Important bit
------------- Whilst every effort has been made to make sure that the
information given in this article is correct neither I or STEN can be
held responsible for any damage which may arise due to readers carrying
out modifications or connecting any devices directly or indirectly to
their computers.
"By order of der Management"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Bibliography - Suggestions for further reading +
+ +
+ ------------ +
+ +
+ Concise Atari ST 68000 Referance Guide by K.D.Peel +
+ +
+ Atari ST Internals by Bruckmann, English & Gerits +
+ +
+ GFA BASIC V3.6 Manual +
+ +
+ Microprocessor Interfacing by R.E.Vears +
+ +
+ Interfacing your BBC Microcomputer by R.Morgan, W.McClean & J.Rosell +
+ +
+ Practical Digital Electronics Handbook by Mike Tooley +
+ +
+ Introducing Atari ST Machine code by Roger Pearson & Sean Hodgson +
+ +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
**************************************************************************
* *
* Dave Price, 42 Foxglove Green, Willesborough, Ashford, Kent. TN24 0RJ *
* *
**************************************************************************